﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Batman.Cms.Domains;
using Batman.Cms.Services.Applications.Filters;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace Batman.Cms.Services.Applications
{
    public class ApplicationReader : ApplicationService
    {
        public IRepository<Application> applicationRepository { get; set; }

        /// <summary>
        /// 查询接口
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public PagedResultDto<Application> Get(ApplicationFilter filter, PagedResultRequestDto page)
        {
            var query = applicationRepository.GetAll().AsNoTracking();

            if (filter.IsDeleted.HasValue)
            {
                query = query.Where(t => t.IsDeleted == filter.IsDeleted);
            }

            var items = query.OrderByDescending(t => t.Id).Skip(page.SkipCount).Take(page.MaxResultCount).ToList();
            var total = query.Count();

            return new PagedResultDto<Application>(total, items);
        }


    }
}
